home *** CD-ROM | disk | FTP | other *** search
- Path: reno.WPI.EDU!vittohue
- From: Jose Andres Giraldez <vittohue@wpi.edu>
- Newsgroups: comp.lang.c
- Subject: Segmentation Error..Newbie needs help.
- Date: Thu, 1 Feb 1996 18:32:38 -0500
- Organization: Worcester Polytechnic Institute
- Message-ID: <Pine.OSF.3.91.960201182953.9997A-100000@reno.WPI.EDU>
- NNTP-Posting-Host: reno.wpi.edu
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
-
-
- earlier today I finished my prog, then I decided to rewrite it in a more
- modular fashion. I rewrote it as seen below. (I still have to rewrite the
- plotting technique).
-
- Please help me find the segemntation fault in this code:
-
-
- /*It works on BIGWPI.wpi.edu*/
-
- #include <stdio.h>
- #include <float.h>
- #include <math.h>
- #include "/cs/cs1005/problems/problem2/test2.h"
-
- int round (int);
-
-
- double conv_theta(double);
- double conv_radius(double);
- double sum_all_radi(double);
- double avg_radius(double);
- double radius_derivations(double, double);
- double rads_to_degrees(double);
-
- /*int count, counter, whole, n_rows, n_columns;
- int j, value;
- int graph;
- float limit;
- float temporary;
- float Pi=3.14159;
- float num;
- float xval = limit;
- double remainder;
- double degrees[N_MEAS];
- double min_rad_deri = 80.0;
- double max_rad_deri = 0.0;
- double derivation[N_MEAS];
- double theta[N_MEAS];
- double radius[N_MEAS];
- double radius_sum; This will find the sum of ALL the radius*/
-
- /* main () is where all my results will be transfered to */
-
- void main ()
- {
- int count;
- double radius_A[N_MEAS];
- double radius_B[N_MEAS];
- double theta_A[N_MEAS];
- double theta_B[N_MEAS];
- double radius_sum;
- double AvgRadius;
- double derivation[N_MEAS];
-
- /*Find all values for the radius & theta conversions*/
- for (count = 0; count < N_MEAS; count++){
-
- radius_B[count]=conv_radius( radius_A[count]); /*Put into Funct. #1*/
- printf("This is radius: %lf",radius_B[count]); /*Shows results*/
-
- theta_B[count]=conv_theta( theta_A[count]);/*Put into Funct. #2*/
- printf("THis is theta: %lf",theta_B[count]); /*Shows results*/
- }
- radius_sum=sum_all_radi(radius_B[count]); /*Put into Funct#3*/
- printf("This is the sum af all radi: %lf",radius_sum); /*Shows results*/
-
- AvgRadius=avg_radius(radius_sum);/*Sets AvgRadius = ret funct#4*/
- printf("THis is the Average radius: %lf",AvgRadius);/*Shows results*/
-
- derivation[count] = radius_derivations(AvgRadius, radius_B[count]);
- printf("THese are the derivations: %lf\n",derivation[count]);
- }
-
- /*FUNCTION #1*/
- /*************************************/
- double conv_radius(double radius_B) /*Funct. #1 Convert to Radius*/
- {
- int count;
- radius_B = sqrt((x[count] * x[count]) + (y[count] * y[count]));
- /*Function above converts the (x,y) arrays into radi*/
- return radius_B;
- }
-
- /*FUNCTION #2*/
- /************************************/
- double conv_theta(double theta_B) /*Funct. #2 Convert to Theta*/
- {
- int count;
- theta_B= atan2(y[count], x[count]);
- /*Function above convertss solves with math.h to get the radians*/
- return theta_B;
- }
-
- /*FUNCTION #3*/
- /**********************************/
- double sum_all_radi(double radius_B) /*Funct. #3 Adds to get radius_sum*/
- {
- int count;
- double radius_sum;
- for (count =0; count <N_MEAS; count++){
- radius_sum = radius_sum + radius_B;
- }
- return radius_sum;
- }
-
- /*FUNCTION #4*/
- /***********************************/
- double avg_radius(double radius_sum)/*Funct. #4 Calculates the avg. radius*/
- {
- return (float) radius_sum / N_MEAS; /*Total sum is / by total size*/
- }
-
- /*FUNCTIOn #5*/
- /***********************************/
- double radius_derivations(double derivation, double radius_B)
- {
- int count;
- double AvgRadius;
- /*Find the deviations from the avg radius*/
- for (count=0; count < N_MEAS; count++)
- {
- double derivation[count];
- derivation[count] = (float) AvgRadius - radius_B;
- }
-
- }
-
- /*Thanx*/
-
- /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
- --- Jose A. Giraldez "vittohueQwpi.edu" Worcester Polytechnic Institute ---
- --- "I want to die quietly like my | EMSEP CLASS '99 ---
- --- Grandfather, not screaming like | Visual WEB. Programming ---
- --- the people in his car." | SHPE & HSA ---
- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
-